
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div id="lineTab" class="tab-pane">
	<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">

		<div class="col-lg-12 text-right" style="padding-right: 0px;">
			<button id="addButton" class="btn btn-info btn-sm" type="button" ><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold redragon-line-button-title">新增计划行</span></button>
			<%-- 
			<button id="searchButton" class="btn btn-default btn-sm" type="button"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
			--%>
		</div><br/>

		<div class="table-responsive">
			<table class="table table-stripped table-hover table-bordered border-top">

				<thead>
					<tr>
						<th width="5%">行号</th>
						<th>物料编码</th>
						<th>物料名称</th>
						<th>单位</th>
						<th>规格</th>
						<th>物料属性</th>
						<th>计划数量</th>
						<th>开工日期</th>
						<th>完工日期</th>
						<th>摘要</th>
						<th width="10%">操作</th>
					</tr>
				</thead>
				<tbody>
					
					<c:forEach items="${requestScope.prodMpsLineList}" var="data" varStatus="status">
					<tr>
						<td>${status.count}</td>
						<td>${data.materialCode}</td>
						<td>${data.materialName}</td>
						<td>${data.materialUnit}</td>
						<td>${data.materialStandard}</td>
						<td>${requestScope.bomPropertyMap[data.bomProperty]}</td>
						<td class="lineQuantity" style="color: #1c84c6 !important;">${data.planQuantity}</td>
						<td><fmt:formatDate value="${data.planStartDate}" pattern="yyyy-MM-dd"/></td>
						<td><fmt:formatDate value="${data.planEndDate}" pattern="yyyy-MM-dd"/></td>
						<td>${data.memo}</td>
						<td>
							<div class="btn-group">
								<button class="btn-white btn btn-xs" onclick="editData(${data.mpsLineId})"><i class="fa fa-edit"></i>&nbsp;编辑</button>&nbsp;
								<button class="btn-white btn btn-xs" onclick="deleteData(${data.mpsLineId})"><i class="fa fa-trash"></i>&nbsp;删除</button>
							</div>
						</td>
					</tr>
					</c:forEach>
					
				</tbody>
				<tfoot>
					<%-- 导入页码 --%>
					<jsp:include page="../../common/pages.jsp"></jsp:include>
				</tfoot>
			</table>

		</div>

	</div>
</div>

<div id="addLineModal"></div>

<script>
	$(document).ready(function() {
		//添加行
		$("#addButton").click(function(){
			getLineModal();
		});
	});
	
	function editData(id){
		getLineModal(id);
	}
	
	function deleteData(id) {
		redragonJS.confirm("确认删除数据？", function(){
			deleteLine(id);
		});
	}
	
	function getLineModal(id){
		$.ajax({
			type: "post",
			url: "web/prodMpsLine/getProdMpsLine",
			data: {"mpsLineId": id, "mpsHeadCode": "${param.mpsHeadCode}"},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				if(data!=""){
					$("#addLineModal").html(data);
					$('#addLineDiv').modal('show');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
	
	function deleteLine(id){
		$.ajax({
			type: "post",
			url: "web/prodMpsLine/deleteProdMpsLine",
			data: {"mpsLineId": id, "mpsHeadCode": "${param.mpsHeadCode}"},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				var json = JSON.parse(data);
				if(json.result=="success"){
					redragonJS.close();
					getLineTab("${param.mpsHeadCode}");
				}else{
					redragonJS.alert("删除行错误");
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
</script> 